<template>
  <Layout type="Service">
    <div class="ol">
      <div class="ol-head">
        <div class="ol-search">
          <span class="font_family icon-sousuo"></span>
          <input
            type="text"
            class="input"
            v-model="searchValue"
            @keydown.enter="handleSearch"
            placeholder="标题"
          />
          <span
            class="font_family icon-shanchu"
            v-show="isClear"
            @click="searchValue = ''"
          ></span>
          <!-- <van-search @search="handleSearch" @clear="handleSearch" v-model="query.search" placeholder="标题" /> -->
        </div>
        <div class="ol-tabs">
          <div
            class="item"
            :class="query.type == '1' ? 'active' : ''"
            @click="chooseType(1)"
          >
            我的
          </div>
          <div
            class="item"
            :class="query.type == '2' ? 'active' : ''"
            @click="chooseType(2)"
          >
            我的团队
          </div>
          <div
            class="item"
            :class="query.type == '3' ? 'active' : ''"
            @click="chooseType(3)"
          >
            全部
          </div>
        </div>
      </div>
      <!-- ol-list -->
      <van-list
        v-model="loading"
        :finished="finished"
        finished-text="没有更多了"
        v-if="!isnodata"
        @load="onLoad"
      >
        <div class="ol-list">
          <div
            class="ol-item"
            v-for="(item, index) in dataList"
            :key="index"
            @click="godetail(item.id, item.title,item.node_id)"
          >
            <div v-if="item.title != 'IT服务单（开发需求）'" class="tips">
              <p>该流程不支持预览，请前往PC端查看</p>
            </div>
            <div class="info">
              <div class="title">{{ item.title }}</div>
              <div class="time">{{ item.date }}</div>
            </div>
            <div class="more-info">
              <div class="desc">
                {{ item.subject }}
              </div>
              <div v-if="item.username" class="name">{{ item.username }}</div>
            </div>
            <div class="current">
              <p>当前节点：{{ item.node_name }}</p>
            </div>
          </div>
        </div>
      </van-list>
      <no-data v-if="isnodata" :noDataText="noDataText"></no-data>
      <!-- <div class="ol-add" v-show="query.type == '1'" @click="handleAdd">
        <span class="font_family icon-xinjian_list"></span>
      </div> -->
    </div>
    <quit></quit>
  </Layout>
</template>
<script>
import Layout from "@/layout";
import { serviceList } from "@/api/service.js";
import NoData from "@/components/noData";
import Quit from "@/components/quit";
export default {
  name: "Service",
  components: {
    Layout,
    NoData,
    Quit,
  },
  mounted() {
    if (this.$route.query.type) {
      this.query.type = this.$route.query.type;
    }
    if (localStorage.getItem("type")) {
      localStorage.removeItem("type");
    }
  },
  watch: {
    searchValue(newVal) {
      this.query.search = newVal;
      if (newVal == "") {
        this.isClear = false;
        this.handleSearch();
      } else {
        this.isClear = true;
      }
    },
  },
  data() {
    return {
      searchValue: "",
      dataList: [],
      isnodata: false,
      query: {
        search: "",
        page: 0,
        type: 1,
      },
      loading: false, // 加载更多相关
      finished: false, // 加载更多相关
      noDataText: "暂无数据",
      isClear: false,
    };
  },
  methods: {
    handleAdd() {
      this.$router.push("/service/detail");
    },

    handleSearch() {
      // 切换类型设置可以加载更多
      this.loading = true;
      this.finished = false;
      // 参数调整
      this.query.page = 1;
      this.dataList = [];
      this.isnodata = false;
      this.getList();
    },
    chooseType(type) {
      // 切换类型设置可以加载更多
      this.loading = true;
      this.finished = false;
      //  重置类型和列表
      this.query.type = type;
      this.dataList = [];
      this.handleSearch();
    },
    // 下拉加载更多要处理下
    getList() {
      serviceList(this.query).then((res) => {
        let data = [];
        if (res.data.length === 0 || res.data.length < 10) {
          this.finished = true;
        }
        if (this.query.type === 2) {
          data = res.data.map((item) => {
            item.check = false;
            return item;
          });
        } else {
          data = res.data;
        }
        this.dataList = this.dataList.concat(data);
        if (this.dataList.length == 0) {
          this.isnodata = true;
        } else {
          this.isnodata = false;
        }
        this.loading = false;
      });
    },
    // 加载更多
    onLoad() {
      this.query.page = this.query.page + 1;
      this.getList();
    },
    //服务单详情
    godetail(listid, title ,nodeId) {
      console.log(title);
      if (title == "IT服务单（开发需求）") {
        this.$router.push({
          path: "/service/detail",
          query: {
            id: listid,
            nodeId:nodeId
          },
        });
      }
    },
  },
};
</script>
<style lang="less" scoped>
.ol {
  background: #f7f9f9;
  padding-top: 102px;
  min-height: calc(100vh - (60px + env(safe-area-inset-bottom)));
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
  box-sizing: border-box;
}
.ol-head {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: #fff;
  padding-top: 15px;
}
// ol-search
.ol-search {
  flex: 1;
  position: relative;
  margin: 0 15px;
  background: #f8f8f8;
  border-radius: 7px;
  height: 37px;
  // line-height: 37px;
  // padding-left: 14px;
  .van-search {
    padding: 0;
    .van-cell {
      background: #f8f8f8;
      border-radius: 7px;
      font-size: 14px;
      color: #313541;
    }
  }
  .input {
    width: 100%;
    display: block;
    height: 36px;
    font-size: 14px;
    padding: 6px 12px 6px 36px;
    border: 0;
    box-sizing: border-box;
    background: #f8f8f8;
    border-radius: 7px;
    &:focus {
      outline: none;
    }
  }
  .icon-sousuo {
    position: absolute;
    top: 50%;
    left: 10px;
    margin-top: -7px;
    font-size: 15px;
    color: #8f92a1;
  }
  .icon-shanchu {
    position: absolute;
    top: 50%;
    right: 10px;
    margin-top: -7px;
    font-size: 15px;
    color: #8f92a1;
  }
  .text {
    font-size: 13px;
    margin-left: 8px;
    color: #8f92a1;
    opacity: 0.7;
  }
}
// ol-tabs
.ol-tabs {
  display: flex;
  height: 40px;
  margin-top: 10px;
  .item {
    flex: 1;
    text-align: center;
    line-height: 40px;
    font-size: 13px;
    color: #313541;
    &.active {
      font-size: 14px;
      font-weight: bold;
      position: relative;
      color: #009966;
      &:after {
        position: absolute;
        content: "";
        left: 50%;
        bottom: 0;
        width: 20px;
        height: 1px;
        margin-left: -10px;
        background: #009966;
      }
    }
  }
}
// ol-list
.ol-list {
  padding-top: 11px;
  .ol-item {
    // height: 78px;
    background: #fff;
    padding: 0 15px;
    margin: 0 15px 9px;
    border-radius: 7px;
    .tips {
      border-bottom: 1px solid #f2f2f2;
      p {
        margin: 0;
        color: #fa4e3e;
        font-size: 12px;
        line-height: 36px;
      }
    }
    .info {
      display: flex;
      padding-top: 14px;
      height: 22px;
      .title {
        flex: 1;
        height: 22px;
        font-size: 16px;
        font-weight: bold;
        line-height: 22px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
      }
      .time {
        width: 80px;
        height: 22px;
        line-height: 22px;
        color: #939dad;
        font-size: 12px;
        text-align: right;
      }
    }
    .more-info {
      margin-top: 6px;
      display: flex;
      flex-direction: row;
      justify-content: space-between;
      align-items: center;
      padding-bottom: 16px;
      border-bottom: 1px solid #f2f2f2;
      // height: 35px;
      .desc {
        // flex: 1;
        color: #313541;
        font-size: 13px;
        height: 17px;
        line-height: 17px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
      }
      .hour {
        width: 50px;
        height: 17px;
        line-height: 17px;
        font-size: 17px;
        font-weight: bold;
        color: #009966;
        text-align: right;
      }
      .name {
        // border-top: 1px solid #f2f2f2;
        color: #313541;
        min-width: 60px;
        font-size: 13px;
        text-align: right;
      }
    }
    .current {
      p {
        color: #313541;
        font-size: 13px;
        padding: 7px 0;
        margin: 0;
      }
    }
  }
}
// ol-add
.ol-add {
  position: fixed;
  right: 21px;
  bottom: calc(81px + env(safe-area-inset-bottom));
  text-align: center;
  line-height: 46px;
  color: #fff;
  width: 46px;
  height: 46px;
  background: #009966;
  border-radius: 50%;
  box-shadow: 0px 3px 12px 1px rgba(0, 153, 102, 0.6);
  span {
    font-size: 36px;
  }
}
</style>